package sort;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/4/1 11:10
 */
public class 荷兰国旗 {


    /*
     荷兰国旗问题
     < x 的放 左边,
     = x 的放中间
     > x 的放右边
     */
    public void partition(int nums[],int aim){
        int l = -1,r = nums.length,i = 0;
        while(i < r){
            if(nums[i] < aim){
              swap(nums,++l,i++);
            }
            else if(nums[i] == aim){
                i++;
            }else{
                swap(nums,i,--r);
            }
        }
    }
    public void swap(int nums[],int i, int j){
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }


    public void sort(int nums[],int l,int r){
//        if()
    }


    @Test
    public void test(){
        int arr[] = {4,5,8,7,7,3,2,6,8,7};
        partition(arr,7);
        System.out.println(Arrays.toString(arr));
    }

}
